<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<%
 '
 ' Copyright 2007 Liu, Xiaokang <4341322@gmail.com>
 ' Blog <http://www.ioio.name/>
 ' 
 ' This file is part of JOS(Judge Online System).
 ' You can see this project at <http://code.google.com/p/judgeonline/>
 ' 
 ' JOS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
 ' published by the Free Software Foundation; either revision 3 of the License, or (at your option) any later revision.
 ' 
 ' JOS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
 ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 ' 
 ' You should have received a copy of the GNU General Public License along with JOS. if not, see
 ' <http://www.gnu.org/licenses/>.
 '
%>
<%Option Explicit%>
<%
	Dim PageTitle
	PageTitle="Register"
%>
<!--#include file="Header.asp"-->
<div id="Main">
<div id="Register">
<%If IsLogin() Then
	Response.Redirect("Home.asp")
	Response.end
Else

Dim Registername,Error_Message
Registername=Request.form("Register")
If Registername="Register" Then
Dim Uid,Username,Password,Password2,Email,DefaultLanguage,RealName,Signature,Sex
Username = LCase(Trim(Request.Form("Username")))
Password = Trim(Request.Form("Password"))
Password2 = Trim(Request.Form("Password2"))
Email= Trim(Request.Form("Email"))
DefaultLanguage=Trim(Request.Form("DefaultLanguage"))
RealName=Trim(Request.Form("RealName"))
Signature=Trim(Request.Form("Signature"))
Sex=Trim(Request.Form("Sex"))
Function Check()
Dim Flag
Flag=True
If Username<>"" Then
	If Len(Username)> 12 Then
		Response.Write("Username must less than 13 characters.<br />")
		Flag=False
	End If

	If Len(Username)< 6 Then
		Response.Write("Username must more than 5 characters.<br />")
		Flag=False
	End If
Else
	Response.Write("Field UserName is INVALID. Please use letters.<br />")
	Flag=False
End If

If Password<>"" Then
	If Len(Password)< 6 Then
		Response.Write("Password must more than 5 characters.<br />")
		Flag=False
	End If
	
	If Len(Password)> 12 Then
		Response.Write("Password must less than 13 characters.<br />")
		Flag=False
	End If
	
	If Password2<>"" Then
		If Password<>Password2 Then
			Response.Write("Field Confirm is not the same as Password.<br />")
			Flag=False
		End If
	Else
		Response.Write("Field Confirm is INVALID.<br />")
		Flag=False
	End If
Else
	Response.Write("Field Password is INVALID.<br />")
	Flag=False
End If

If Email<>"" Then
	If Not CheckEmail(Email) Then
		Response.Write("Field Email is INVALID.<br />")
		Flag=False
	End If
Else
	Response.Write("Field Email is INVALID.")
	Flag=False
End If

Check=Flag

End Function



If Check() Then
    
	conn.Open connstr
	Dim Rs
	set rs=server.CreateObject("ADODB.Recordset")
	rs.Open "select * from Members Where Username='"&Username&"'",conn,1,3

	If Rs.BOF and Rs.EOF Then
	Rs.AddNew
	Rs("Username")=Username
	Rs("Password")=Password	
	Rs("Admin")=6
	rs("Email")=Email
	Rs("Gid")=6
	If Sex=1 Or Sex=0 Then
	Rs("Sex")=Sex
	End If
	Rs("DefaultLanguage")=DefaultLanguage
	Rs("RealName")=RealName
	Rs("Signature")=Signature
	Rs("RegIP")=Request.ServerVariables("REMOTE_ADDR")
	Rs("RegTime")=Now()
	Rs("LastIP")=Request.ServerVariables("REMOTE_ADDR")
	Rs("LastTime")=Now()
	rs.Update
	Uid=rs("Uid")
	rs.Close
	set rs=Nothing
	conn.Close
	Response.Write("Register Successful")
	'Response.Redirect("Login.asp")
	'Response.End
	Else
	rs.Close
	set rs=Nothing
	conn.close
	Response.Write("Username already exists")
    End If
End If
Else
%>
  <div id="RegisterTable">
  <form name="form1" method="post" action="Register.asp">
      <table>
	      <tr>
            <td colspan="2" align="center">New Member Register</td>          
          </tr>
          <tr>
            <td >Username:</td>
            <td ><input name="username" type="text" id="username"  maxlength="12" /></td>
          </tr>
          <tr>
            <td>Password:</td>
            <td><input name="password" type="password" id="password" maxlength="12" /></td>
          </tr>
          <tr>
            <td>Confirm:</td>
            <td><input name="password2" type="password" id="password2" maxlength="12" /></td>
          </tr>
		  <tr>
            <td>E-mail:</td>
            <td><input name="email" type="text" id="email" maxlength="32" /></td>
          </tr>
          <tr>
            <td>Language:</td>
            <td>
            <select id="DefaultLanguage" name="DefaultLanguage">
      			<option value="C">C</option>
                <option value="CPP" selected="selected">C++</option>
                <option value="JAVA">JAVA</option>
    		</select>			</td>
          </tr>
          <tr>
            <td>School:</td>
            <td><input name="school" type="text" id="school" maxlength="32" /></td>
          </tr>
          <tr>
            <td>RealName:</td>
            <td><input name="realname" type="text" id="realname" maxlength="32" /></td>
          </tr>
          <tr>
            <td>Sex:</td>
            <td>
            <select id="Sex" size="3" name="Sex">
            	<option value="-1" selected="selected">Secret</option>
      			<option value="0">Female</option>
                <option value="1">Male</option>
    		</select>
            </td>
          </tr>
          <tr>
            <td>SNo:</td>
            <td><input name="sno" type="text" id="sno" maxlength="32" /></td>
          </tr>
          <tr>
            <td>Telphone:</td>
            <td><input name="telphone" type="text" id="telphone" maxlength="32" /></td>
          </tr>
          <tr>
            <td>Signature:</td>
            <td><textarea name="Signature" cols="40" rows="5" id="Signature"></textarea></td>
          </tr>
          <tr>
            <td >&nbsp;</td>
            <td>
 				<input type="submit" name="Register" value="Register"/></td>
          </tr>
        </table>
    </form></div>
<%End If
End If%>
</div>
</div>
<!--#include file="Footer.asp"-->
